var time_id = null;

function animate(element,current,target,step){
  if(element.time_id){
      clearInterval(element.time_id);
      element.time_id = null;
  };
  element.time_id = setInterval(function(){
    //判断如果当前位置大于目标位置,说明往回走,step为负数
    if(current > target){
      step = -Math.abs(step);
    }
    if(Math.abs(current-target) <= Math.abs(step)){
      current = target;
      clearInterval(element.time_id);
    }else{
      current += step;
    };
    element.style.left = current + 'px';
  },30);
};
